package exercicis_t3_java.tema3_part2.q10;

import java.text.NumberFormat;
import java.util.Scanner;

public class Estad1 {

	public static void main(String arg[]) {
		int tam = 5;
		int miArray[] = new int[tam];

		Scanner sc = new Scanner(System.in);
		System.out.println("intro nota1: ");
		miArray[0] = Integer.parseInt(sc.next());
		System.out.println("intro nota2: ");
		miArray[1] = Integer.parseInt(sc.next());
		System.out.println("intro nota3: ");
		miArray[2] = Integer.parseInt(sc.next());
		System.out.println("intro nota4: ");
		miArray[3] = Integer.parseInt(sc.next());
		System.out.println("intro nota5: ");
		miArray[4] = Integer.parseInt(sc.next());

		double aux_media = Estad1.media(miArray);
		// double aux_media = Calculo.media(miArray); //ara crido a la classe
		// Calculo, metode media
		System.out.println(" media : " + aux_media);
		double aux_var = Estad1.varianza(miArray, aux_media);

		NumberFormat nf = NumberFormat.getInstance();
		nf.format(aux_var);
		System.out.println(" varianza : " + aux_var);
		nf.format(Math.sqrt(aux_var));
		System.out.println(nf.format(Math.sqrt(aux_var)));

		sc.close();
	}

	public static double media(int arr[]) {
		double sum = 0.0;
		for (int i = 0; i < arr.length; i++) {
			sum += arr[i];
		}
		return sum / arr.length;
	}

	public static double varianza(int arr[], double media) {
		double sum = 0.0;
		for (int i = 0; i < arr.length; i++) {
			sum += Math.pow(arr[i] - media, 2);
		}
		return sum / (arr.length - 1);
	}
}
